package cos.parser;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import cos.entity.LyricsResponse;
import cos.entity.ParserName;
import cos.entity.Song;

public class LocalArchiveParser implements Parser {

	@Override
	public LyricsResponse getLyrics(Song song) {
		BufferedReader br = null;
		try {
			// open file
			br = new BufferedReader(new FileReader("lyrics/"
					+ song.getArtistForFile() + "/" + song.getTitleForFile()
					+ ".txt"));

			StringBuilder sb = new StringBuilder();

			// Read first line
			String line = br.readLine();
			while (line != null) {
				sb.append(line);
				sb.append('\n');
				line = br.readLine();
			}
			return new LyricsResponse(sb.toString(), ParserName.LOCAL);
		} catch (Exception e) {
		} finally {
			// close buffered reader
			if (br != null)
				try {
					br.close();
				} catch (IOException e) {
				}
		}
		// houston, we have a problem
		return null;
	}
}
